import {createRouter, createWebHashHistory, createWebHistory} from "vue-router";
import {ss_setItem} from "@/assets/common/js/utils";
import store from '@/store/index'

//自动引入路由文件;
const files = require.context(".", true, /\.js$/);
let modules = [];
files.keys().forEach((key) => {
  if (key === "./index.js") return;
  modules.push(...files(key).default);
});

const routes = [...modules];

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});

router.beforeEach((to, from, next) => {
  let timer = setTimeout(() => {
    let flag = to.name === 'login';
    store.commit('common/GET_IS_LOGIN_PAGE', flag);
    next();
  }, 5);
})

window.addEventListener("popstate", function (e) {
  store.commit('common/GET_IS_PAGE_BACK', true);
}, false);

export default router;
